home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
linuxcon.000
/
linuxcon
/
linuxconf-1.6
/
userconf
/
userconf.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-20
|
4KB
|
150 lines
#pragma implementation
#include <unistd.h>
#include "../xconf/xconf.h"
#include "internal.h"
#include "userconf.h"
#include "../paths.h"
#include "userconf.m"
static USERCONF_HELP_FILE help_intro ("intro");
void userconf_edit()
{
/* #Specification: userconf / principal
The userconf program allows you to edit/create/delete user
accounts and groups.
*/
int choice=0;
while (1){
static const char *user_accounts = MSG_U(M_USER,"user accounts");
static const char *groupe_def = MSG_U(M_GROUPDEF,"group definitions");
static const char *users_pass = MSG_U(M_UPASS,"users password");
static const char *root_pass = MSG_U(M_ROOTPASS,"root password");
static const char *std_ppp = MSG_U(M_PPP,"PPP account via normal login");
static const char *pap_ppp = MSG_U(M_PPPPAP,"PPP account via PAP authentication");
static const char *chap_ppp = MSG_U(M_PPPCHAP,"PPP account via CHAP authentication");
static const char *std_slip = MSG_U(M_SLIP,"SLIP account via normal login");
static const char *uucp_account = MSG_U(M_UUCP,"UUCP account");
static const char *pop_accounts = MSG_U(M_POP,"POP accounts (mail only)");
static const char *passwd_policies = MSG_U(M_POLICIES,"Password setting policies");
static const char *menuopt[]={
MSG_U(M_ECREATE,"Edit/Create"), user_accounts,
" ", groupe_def,
MSG_U(M_CHANGE,"Change"), users_pass,
" ", root_pass,
"-", "Special accounts",
MSG_R(M_ECREATE), std_ppp,
" ", pap_ppp,
" ", chap_ppp,
" ", std_slip,
" ", uucp_account,
" ", pop_accounts,
"-", "",
MSG_U(M_EDIT,"Edit"), passwd_policies,
NULL
};
MENU_STATUS code = xconf_menu (
MSG_U(T_UCONF,"User account configurator")
,MSG_U(I_UCONFINTRO
,"This package allows you to add/delete\n"
"and manage user accounts\n")
,help_intro
,menuopt,choice);
if (code == MENU_QUIT || code == MENU_ESCAPE){
break;
}else{
const char *key = menuopt[choice*2+1];
if (key == user_accounts){
users_edit(NULL);
}else if (key == pop_accounts){
USER *like;
if (special_init (POP_GROUP,like) != -1){
users_edit(like);
}
delete like;
}else if (key == std_ppp){
USER *like;
if (special_init (PPP_GROUP,like) != -1){
users_edit(like);
}
delete like;
}else if (key == std_slip){
USER *like;
if (special_init (SLIP_GROUP,like) != -1){
users_edit(like);
}
delete like;
}else if (key == uucp_account){
USER *like;
if (special_init (UUCP_GROUP,like) != -1){
users_edit(like);
}
delete like;
}else if (key == pap_ppp){
}else if (key == chap_ppp){
}else if (key == groupe_def){
groups_edit();
}else if (key == passwd_policies){
PASSWD_VALID vl;
vl.edit();
}else if (perm_rootaccess(
MSG_U(P_CHGPASS,"change users password"))){
USERS users;
int save_ok = -1;
if (key == users_pass){
save_ok = users.editpass(NULL);
}else if (key == root_pass){
USER *root = users.getitem("root");
SHADOW *shadow = users.getshadow(root);
save_ok = root->editpass(0,shadow);
}
if (save_ok != -1) users.write();
}
}
}
}
/*
Edit the password of the current user or one specific user
*/
int userconf_passwd (int argc, char *argv[])
{
USERS users;
int save_ok = -1;
if (argc == 1){
USER *usr = users.getfromuid(getuid());
SHADOW *shadow = users.getshadow (usr);
if (usr == NULL){
xconf_error (
MSG_U(E_NOUID,"Can't locate entry for uid %d\n"
"in %s"),getuid(),ETC_PASSWD);
}else{
if (isatty(0) && isatty(1)){
dialog_clear();
save_ok = usr->edithispass(shadow);
}else{
save_ok = usr->edithispass_notty(shadow);
}
if (save_ok != -1) perm_forceok(); // This let the write
// succeed
}
}else if (argc == 2){
USER *usr = users.getitem(argv[1]);
if (usr == NULL){
xconf_error (MSG_U(E_UNKNOWNUSER,"Unknown user %s\n"),argv[1]);
}else if (perm_rootaccess(MSG_R(P_CHGPASS))){
SHADOW *shadow = users.getshadow (usr);
dialog_clear();
save_ok = usr->editpass(1,shadow);
}
}
if (save_ok != -1) users.write();
return 0;
}
int userconf_main (int , char *[])
{
userconf_edit();
return 0;
}